package com.lzy.aspectj;

import com.lzy.annotation.AuthCheck;
import com.lzy.utils.PermissionUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 权限校验
 *
 * @author lyw
 * @Date 2023/2/16-上午11:58
 */
@Slf4j
@Aspect
@Component
public class AuthCheckAspect {

  @Autowired
  private PermissionUtil permissionUtil;

  @Around("execution(* com.lzy..*Controller.*(..)) && @annotation(ac)")
  public Object doAround(ProceedingJoinPoint pjp, AuthCheck ac) throws Throwable {

    permissionUtil.checkPermission(ac);
    return pjp.proceed();
  }
}
